package com.liyang.springcloud.controller;

import com.liyang.springcloud.common.entities.CommonResult;
import com.liyang.springcloud.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @BelongsProject: cloud-2024
 * @BelongsPackage: com.liyang.springcloud.controller
 * @Author: liyang
 * @CreateTime: 2024-01-10  11:05
 * @Description: 库存服务
 * @Version: 1.0
 */
@RestController
@Slf4j
@RequestMapping("/storage")
public class StorageController {

    @Resource
    private StorageService storageService;

    /**
     * @description: 扣减库存
     * @author: liyang
     * @date: 2024/1/10 11:07
     * @param: productId 产品id
     * @param: count 数量
     * @return: com.liyang.springcloud.common.entities.CommonResult
     **/
    @PostMapping ("/decrease")
    public CommonResult decrease(Long productId, Integer count) {
        storageService.decrease(productId, count);
        return new CommonResult(200, "扣减库存成功！");
    }
}
